<template>
  <div class="row">
    <div @click="minusCount">
      <div
        class="iconWrapper"
        :style="{ 'background-color': buyCount <= 1 ? '#f5f5f5' : '#4fac91' }"
      >
        <van-icon name="minus" />
      </div>
    </div>
    <text
      :style="{
        'font-size': '20px',
        width: width || '70px',
        'text-align': 'center',
      }"
      >{{ buyCount }}</text
    >
    <div @click="addCount" class="iconWrapper">
      <van-icon name="plus" />
    </div>
  </div>
</template>

<script setup>
import { ref, defineProps } from 'vue';

const props = defineProps(['onCountChange', 'width']);
const buyCount = ref(1);

function addCount() {
  buyCount.value++;
  props.onCountChange(buyCount.value);
}
function minusCount() {
  if (buyCount.value <= 1) {
    return;
  }
  buyCount.value--;
  props.onCountChange(buyCount.value);
}
</script>

<style lang="scss" scoped>
.row {
  display: flex;
  flex-direction: row;
}

.iconWrapper {
  background-color: #4fac91;
  border-radius: 9999px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}
</style>
